﻿using JetBrains.ReSharper.Feature.Services.Bulbs;
using JetBrains.ReSharper.Feature.Services.CSharp.Bulbs;
using JetBrains.ReSharper.Psi;
using MugenMvvmToolkit.ReSharper.Infrastructure;

namespace MugenMvvmToolkit.ReSharper.Arguments.ContextActions
{
    [ContextAction(Name = "NotBeNullOrEmptyContextAction", Group = "C#", Priority = 100)]
    public class NotBeNullOrEmptyContextAction : ArgumentContextAction
    {
        #region Constructors

        public NotBeNullOrEmptyContextAction(ICSharpContextActionDataProvider provider)
            : base(provider)
        {
        }

        #endregion

        #region Overrides of ArgumentContextActionBase

        /// <summary>
        ///     Popup menu item text
        /// </summary>
        public override string Text
        {
            get { return UiResources.AddNotBeNullOrEmpty; }
        }

        protected override IMethod Method
        {
            get { return MethodProvider.ShouldNotBeNullOrEmptyEnumerable; }
        }

        /// <summary>
        ///     Gets a value indicating whether IsArgumentTypeCompatible.
        /// </summary>
        /// <returns>
        ///     <c>true</c> if the argument type is of the expected type, otherwise <c>false</c>.
        /// </returns>
        protected override bool IsExpectedArgumentType(IParameter declaredElement)
        {
            return declaredElement != null && declaredElement.Kind != ParameterKind.OUTPUT
                   && !declaredElement.Type.IsString() && declaredElement.Type.IsOfType(TypeProvider.EnumerableInterface);
        }

        #endregion
    }
}